package com.example.littleSpider.myapplication.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.activity.BuyingSpreeActivity;
import com.example.littleSpider.myapplication.activity.GoodsDetailsActivity;
import com.example.littleSpider.myapplication.activity.MallsActivity;
import com.example.littleSpider.myapplication.base.BaseFragment;
import com.littlespider.mylibrary.util.T;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by aduser on 2017/12/5.
 */

public class EspeciallySaleFragment extends BaseFragment {

    @BindView(R.id.image_banner)
    MZBannerView mzBannerView;
    @BindView(R.id.ll_goods)
    LinearLayout ll_goods;
    @BindView(R.id.ll_malls)
    LinearLayout ll_malls;

    int[] imageArray = {R.drawable.timg_one, R.drawable.timg_two, R.drawable.timg_three};
    List imageList = new ArrayList();

    @Override
    public int setLayout() {
        return R.layout.fragment_especially_sale;
    }

    @Override
    protected void initView() {
        imageList.add(R.drawable.timg_one);
        imageList.add(R.drawable.timg_two);
        imageList.add(R.drawable.timg_three);
        mzBannerView.setIndicatorRes(R.drawable.indicator_normal, R.drawable.shape_indicator_orange);
        mzBannerView.setPages(imageList, new MZHolderCreator() {
            @Override
            public MZViewHolder createViewHolder() {
                return new BannerViewHolder();
            }
        });

        for (int i = 0; i < 10; i++) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.include_things_view, null);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), GoodsDetailsActivity.class);
                    startActivity(intent);
                }
            });
            ll_goods.addView(view);
        }
        for (int i = 0; i < 2; i++) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_especially_sale, null);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    T.show(getContext(), "enter");
                    Intent intent = new Intent(getActivity(), MallsActivity.class);
                    intent.putExtra("title", "市集");
                    startActivity(intent);
                }
            });
            ll_malls.addView(view);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mzBannerView.start();
            }
        }, 1000);
    }

    @Override
    public void onPause() {
        super.onPause();
        mzBannerView.pause();
    }

    @OnClick(R.id.rl_buying)
    public void intoBuying(){
        Intent intent = new Intent(getActivity(), BuyingSpreeActivity.class);
        startActivity(intent);
    }

    class BannerViewHolder implements MZViewHolder<Integer>{

        ImageView imageView;
        @Override
        public View createView(Context context) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.view_banner, null);
            imageView = (ImageView) view.findViewById(R.id.image);
            return view;
        }

        @Override
        public void onBind(Context context, int i, Integer integer) {
            imageView.setImageResource(integer);
        }
    }
}
